<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,user-scalable=no, initial-scale=1">
		<title>添加拜访记录</title>
	    <link rel="stylesheet" type="text/css" href="../static/azxcrm/css/wap/aui.css" th:href="@{/azxcrm/css/wap/aui.css}" />
	    <link rel="stylesheet" type="text/css" href="../static/azxcrm/css/wap/aui.css" th:href="@{/azxcrm/css/wap/mui.min.css}" />
	    <link rel="stylesheet" type="text/css" href="../static/azxcrm/css/wap/aui.css" th:href="@{/azxcrm/css/wap/mui.picker.min.css}" />
	    <link rel="stylesheet" type="text/css" href="../static/azxcrm/css/wap/aui.css" th:href="@{/azxcrm/css/wap/add_visit.css}" />			
		<link rel="stylesheet" type="text/css" href="//at.alicdn.com/t/font_835360_5n3z54a5m1.css"/>
		<script src="/azxcrm/js/wap/mui.min.js" th:src="@{/azxcrm/js/wap/mui.min.js}" type="text/javascript" charset="utf-8"></script>
        <script src="/azxcrm/js/wap/mui.picker.min.js" th:src="@{/azxcrm/js/wap/mui.picker.min.js}" type="text/javascript" charset="utf-8"></script>
        <script src="/azxcrm/js/wap/city.data-3.js" th:src="@{/azxcrm/js/wap/city.data-3.js}" type="text/javascript" charset="utf-8"></script>
		<script src="../static/js/jquery.min.js" th:src="@{/js/jquery.min.js}"></script>
		<script th:inline="javascript"> var ctx = [[@{/}]]; </script>
	</head>
	<body>
		<header class="aui-bar aui-bar-nav">
			 <a href="javascript:history.back(-1)" class="aui-pull-left aui-btn">
	       		 <span class="iconfont icon-fanhui1">返回</span>
	    	</a>
		    <div class="aui-title">添加跟单记录</div>
		</header>
		<form id="orderFollowAdd">
		<section class="aui-grid aui-margin-b-15">
			<div class="aui-content aui-margin-b-15">
			    <ul class="aui-list aui-list-in">		       
			        <li class="aui-list-item">
			            <div class="aui-list-item-inner aui-list-item-arrow" id="phone">
			            	<div class="clearfix">
			            		<div class="aui-list-item-title">拜访类型：</div>	
			                	<div class="aui-text">选择拜访类型</div>
			                	<input type="hidden" id="visitId" name="visitId">
                                <input type="hidden" id="visitType" name="visitType">
                                <input type="hidden" id="status" name="status" th:value="${status}">
			            	</div>			                
			            </div>
			        </li>		
			    </ul>
			</div>
			
			<div class="aui-content aui-margin-b-15 g-order2">
				<ul class="aui-list aui-form-list">
			        <li class="aui-list-header">
						<div class="s-order">
							<div class="g-jl">沟通记录</div>
						</div>
			        </li>
					<li class="aui-list-item">
			            <div class="aui-list-item-inner">
			                <div class="aui-list-item-input">
			                    <textarea placeholder="请填写沟通记录" id="visitRecord" name="visitRecord"></textarea>
			                </div>
			            </div>
			        </li>
			        <li class="aui-list-header">
						<div class="s-order">
							<div class="g-jl">备注</div>
						</div>
			        </li>
					<li class="aui-list-item">
			            <div class="aui-list-item-inner">
			                <div class="aui-list-item-input">
			                    <textarea class="g-remark" placeholder="请填写备注" id="visitRemark" name="visitRemark"></textarea>
			                </div>
			            </div>
			       </li>
			   </ul>
		   </div>
		   <div class="aui-content aui-margin-b-15">
                <ul class="aui-list aui-list-in g-ul">             
                    <li class="aui-list-item g-appoint" id="date">
                        <div class="aui-list-item-inner aui-list-item-arrow">
                            <div class="aui-list-item-label">拜访时间：</div>
                            <div class="aui-list-item-input input1">
                            <div class="aui-text" id="select-date">请选择日期</div>
                             <input type="hidden" id="visitTime"  name="visitTime" >
                            </div>                      
                        </div>  
                    </li>   
                    <li class="aui-list-item g-appoint" id="date2">
                        <div class="aui-list-item-inner aui-list-item-arrow">
                        <div class="aui-list-item-label">下次约定：</div>
                            <div class="aui-list-item-input input1">
	                             <div class="aui-text" id="select-date2">请选择日期</div> 
	                             <input type="hidden" id="visitTimeNest"  name="visitTimeNest" >
                            </div>                      
                        </div>
                    </li>
                </ul>
		   </div>
			<footer class="aui-bar aui-bar-tab" id="footer"> 
			         <input type="hidden" id="orderId" name="orderId" th:value="${order.orderId}">
			         <input type="hidden" id="status" name="status" th:value="${status}">               
			         <button type="button" class="aui-bar" id="toastBtn" onclick="return check(this.form)">添加记录</button>        
		   </footer>
		</section>
		</form>
	</body>
</html>

<script>
    var arr = [];
	var data = document.getElementById("date"); 
	var data2 = document.getElementById("date2")
	var phone = document.getElementById("phone");
	var orderId = document.getElementById("orderId").value;
	$.ajax({
        cache : true,
        type : "get",
        url : ctx + "/wap/getVisit",
        data :'',
        async : false,
        error : function(res) {
        	mui.toast("系统错误", "res");
        },
        success : function(data) {   
            for(var i=0;i<data.length;i++){
                arr.push({
                    value:data[i].dictCode,
                    text:data[i].dictLabel
                })
            
            }   
            Init(arr);
        }
        });
	
	
	function Init(arr){
	   var phone_data= new mui.PopPicker(); 
		phone_data.setData(arr)
		phone.addEventListener('tap', function() {
			phone_data.show(function(items) {
				document.getElementsByClassName('aui-text')[0].innerText = items[0].text;
                document.getElementById('visitId').value = items[0].value;
                document.getElementById('visitType').value = items[0].text;
				//返回 false 可以阻止选择框的关闭
				//return false;
			});
		}, false);
		   data.addEventListener('tap', function() {
		        var picker = new mui.DtPicker({type:'date'});
		          picker.show(function(rs) {
		        	  console.log(rs.text)
		        	  var input1=document.getElementById('select-date')
		            input1.innerText = rs.text;
		            document.getElementById('visitTime').value = rs.text;
		            picker.dispose();
		          });
		    })  
            data2.addEventListener('tap', function() {
            var picker = new mui.DtPicker({type:'date'});
              picker.show(function(rs) {
            	var input2=document.getElementById('select-date2')
                input2.innerText = rs.text;
                document.getElementById('visitTimeNest').value = rs.text;
                picker.dispose();
              });
        })	

		   }
	
	function check(form) {
		 var status = document.getElementById("status").value;
         if(form.visitType.value==''){
            mui.toast('拜访类型必选');
              return false;
           }else if(form.visitRecord.value=='') {                
             mui.toast('沟通记录必填');
               form.visitRecord.focus();
               return false;
          }else if(form.visitTime.value=='') {                
              mui.toast('拜访时间必选');
              form.visitTime.focus();
              return false;
          }else{ 
             $.ajax({
             cache : true,
             type : "POST",
             url : ctx + "/wap/saveRecord",
             data : $("#orderFollowAdd").serialize(),
             async : false,
             error : function(request) {
            	 mui.toast("系统错误", "error");
             },
             success : function(data) {
                 if (data.code == 0) {
                     mui.toast("添加成功");
                     if(status == 0){
                    	 $("#toastBtn").removeAttr("onclick");
                         setTimeout(function(){
                             window.location.href= ctx + "wap/wapOrderDetail?orderId=" + orderId+"&status=" + status
                             },2200)
                     }else if(status == 1){
                    	 $("#toastBtn").removeAttr("onclick");
                    	 setTimeout(function(){
                             window.location.href= ctx + "wap/wapOrderDetail?orderId=" + orderId+"&status=" + status
                             },2200)
                     }
                 } else {
                     mui.toast("添加失败");
                 }
             }
             });
          }     
    }

</script>
